package com.eascs.web.o2o.web.controller;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eascs.app.dao.PageResult;
import com.eascs.common.util.UrlUtil;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.view.BaseRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.Button;
import com.eascs.site.view.button.ButtonHelper;
import com.eascs.tag.MenuTag;
import com.eascs.web.o2o.web.common.BaseMasterViewController;
import com.eascs.web.o2o.web.entity.WfEmail;
import com.eascs.web.o2o.web.form.MailForm;
import com.eascs.web.o2o.web.service.IMessageService;

@Controller
@RequestMapping("/message")
public class MessageController extends BaseMasterViewController {

	@Autowired
	IMessageService messageService;
	
	@Override
	public void preHandle() {
		super.preHandle();
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "mailManage");
	}
	
	
	@RequestMapping(value="/getMailBaseInfo")
	public String getMailBaseInfo(MailForm vo){
		vo.setPageSize(10);
		PageResult<Object[]> pageResult= messageService.findMailBaseInfo(vo);
	  
		//SelectDataOption[] selectDataOptions = { new SelectDataOption("messageSysType"), null, null, null, null, null, null };
        String[] titles = {"请求系统编码", "请求系统流水","邮件类型编码","发送类型","邮件标题","创建时间","发送状态"};
		String pageUrl="/message/getMailBaseInfo";
		
		pageUrl = UrlUtil.appendUrl(pageUrl,"systemCode",vo.getSystemCode());
		pageUrl = UrlUtil.appendUrl(pageUrl,"requestId",vo.getRequestId());
		pageUrl = UrlUtil.appendUrl(pageUrl,"mailSendType",vo.getMailSendType());
		pageUrl = UrlUtil.appendUrl(pageUrl,"title",vo.getTitle());
		pageUrl = UrlUtil.appendUrl(pageUrl,"createTime",vo.getCreatTime());
		pageUrl = UrlUtil.appendUrl(pageUrl,"status",vo.getStatus());
		pageUrl = UrlUtil.appendUrl(pageUrl,"beginTime",vo.getBeginTime());
		pageUrl = UrlUtil.appendUrl(pageUrl,"endTime",vo.getEndTime());
		pageUrl = UrlUtil.appendUrl(pageUrl, "showPage", "");
		
		
		
		Button[] titleButtons = new Button[] { ButtonHelper.createOpenButton(null , "/message/detail?emailId=") };
		
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, pageUrl);
		paginationInfo.setBuildPagingNavigation(true);
		paginationInfo.setFirstRenderColumnIndex(1); //开始显示的列
		//paginationInfo.setSelectDataOptions(selectDataOptions);
		paginationInfo.setTitleButtons(titleButtons);
		//paginationInfo.setFormats(new Format[] { null, null, null, null, new DecimalFormat(",##0.00"), null, null, null, null });
		ViewContext.put("paginationInfo", paginationInfo);
		
		List<Object[]> EmailSystemType =messageService.findEmailSystemType();
		if(EmailSystemType!=null&&EmailSystemType.size()>0){
			ViewContext.put("EmailSystemType", EmailSystemType.get(0));
		}
		ViewContext.put("vo", vo);
		BaseRestResult.refresh();
		return "/message/mail_list";
		
		
	}
	
	@RequestMapping("/detail")
	public String detail(String emailId){
		WfEmail wfEmail = messageService.findDetailByEmailId(emailId);
		ViewContext.put("wfEmail", wfEmail);
		return "message/mail_detail";
	}
	
	
	
	
}
